package com.filter;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//@WebFilter(urlPatterns = "/*", filterName = "CORSFilter")
//public class CORSFilter implements Filter {
// @Override
// public void destroy() {
// }
// /**
//  * 此过滤器只是处理跨域问题
//  * @param servletRequest
//  * @param servletResponse
//  * @param chain
//  * @throws ServletException
//  * @throws IOException
//  */
// @Override
// public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws ServletException, IOException {
//  HttpServletRequest req = (HttpServletRequest) servletRequest;
//  HttpServletResponse resp = (HttpServletResponse) servletResponse;
//  String origin = req.getHeader("Origin");
//  if(origin == null) {
//   origin = req.getHeader("Referer");
//  }
//  System.out.println("---------------------------5555555--------------------------");
//  System.out.println(origin);
//  resp.setHeader("Access-Control-Allow-Origin", origin);//这里不能写*，*代表接受所有域名访问，如写*则下面一行代码无效。谨记
//  resp.setHeader("Access-Control-Allow-Credentials", "true");//true代表允许携带cookie
//
//  //当**Credentials为true时，**Origin不能为星号，需为具体的ip地址【如果接口不带cookie,**Origin无需设成具体ip】
//  resp.setHeader("Access-Control-Allow-Credentials", "true");
//  resp.setHeader("Access-Control-Allow-Methods", "GET,POST,PATCH,PUT,OPTIONS,DELETE");
//  resp.setHeader("Access-Control-Allow-Headers", "Origin,Content-Type,Cookie,Accept,Token");
//  chain.doFilter(servletRequest,servletResponse);
// }
// @Override
// public void init(FilterConfig filterConfig) throws ServletException {
// }
//}